package com.sy.crm.action;

import java.util.ArrayList;
import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.sy.util.Datas;

public class AutocompleterAction extends ActionSupport {
    private static final long serialVersionUID = -8201401726773589361L;
    
    private List<String[]> names;    
    private String start;
    
    public void setStart(String start) {
        this.start = start;
    }
    
    public List<String[]> getNames() {
        return names;
    }

    public String execute() {
        names = new ArrayList<String[]>();
        if(start == null || "".equals(start.trim())){
            start = "a";
            start = "b";
            start = "c";
            start = "d";
            start = "e";
            start = "f";
            start = "g";
            start = "h";
            start = "i";
            start = "j";
            start = "k";
            start = "l";
            start = "m";
            start = "n";
            start = "o";
            start = "p";
            start = "q";
            start = "r";
            start = "s";
            start = "t";
            start = "u";
            start = "v";
            start = "w";
            start = "x";
            start = "y";
            start = "z";
        }
        for(String s : Datas.NAMES) {
            if(s.toLowerCase().startsWith(start.toLowerCase())) {
                names.add(new String[]{s,s});
            }
        }
        return SUCCESS;
    }
}